<?php

class Core_Backend_Component_Promotion_Controller_Helper extends Dcmp_Component_Controller {

    public function chooseConcessionsAction($title = '', $callback = '', $isself = '', $elementid = '', $selected = '', $poi = '', $sort = 'id', $dir = 'asc') {
        $this->getHistory()->record();
        $validator = $this->getRequest()->getValidator('filter');
        $collection = App::getModel('promotion/collection_concessions')
                        ->pagination(1, 50)
                        ->sortBy($sort, $dir);
        $collection->filterByStatus('published');
        if ($validator->isNotEmpty('name')) {
            $collection->filterByName($validator->getValue('name'));
        }
        if ($validator->isNotEmpty('tag')) {
            $collection->filterByTag($validator->getValue('tag'));
        }
        if ($validator->isNotEmpty('categoryname')) {
            $collection->filterByCategoryName($validator->getValue('categoryname'));
        }
        if (!empty($selected)) {
            $ids = explode(',', $selected);
            Kd_Util_Array::removeEmpty($ids);
            if (!empty($ids)) {
                $collection->not()->contain('a.id', ':ids:i')->addParameter('ids', $ids);
            }
        }
        if (!empty($poi)) {
            $collection->where()->inQuery('a.id')
                    ->from('{t}promotion_concessions_poi')
                    ->field('a.concessions_id')
                    ->contain('poi_ids', ':poiIds:s')
                    ->addParameter('poiIds', explode(',', $poi));
        }
        $collection->load();
        return $this->viewResult(
                array('list' => $collection,
                    'element_id' => $elementid,
                    'callback' => $callback,
                    'selected' => $selected,
                    'is_self' => $isself,
                    'poi' => $poi,
                    'title' => $title));
    }

}